jQuery(document).ready(function () {
	$( "input[name=birthday]" ).datepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true, yearRange: "1900:2012" });
	
	$("#registerPage form input, #registerPage form select").focus(function () {
		$(this).parents("label").removeClass("error");
	});
	
	//Get city
	
	//Get district
	$("select[name=city]").bind("change", changeCity);
	function changeCity() {
		var id = $(this).val();
		loadDistrict(id, "");
	}
	
	//Get ward
	$("select[name=district]").bind("change", changeDistrict);
	function changeDistrict() {
		var id = $(this).val();
		loadWard(id, "");
	}
	
});

function loadCity(selected) {
	$.ajax({
		type: "POST",
		url: "/ajax-get-city",
		data: {},
		dataType: "html",
		success: function(response)
		{
			$("select[name=city]").html(response);
			$("select[name=city]").val(selected);
		}
	});
}

function loadDistrict(id, selected) {
	$.ajax({
		type: "POST",
		url: "/ajax-get-district",
		data: {id: id},
		dataType: "html",
		success: function(response)
		{
			$("select[name=district]").html(response);
			$("select[name=district]").val(selected);
		}
	});
}

function loadWard(id, selected) {
	$.ajax({
		type: "POST",
		url: "/ajax-get-ward",
		data: {id: id},
		dataType: "html",
		success: function(response)
		{
			$("select[name=ward]").html(response);
			$("select[name=ward]").val(selected);
		}
	});
}